Mac OS 8.5 Technote: Part XXXVII

Copyright 1998 by Apple Computer, Inc. All Rights Reserved.

[Previous section] [Mac OS 8.5 Contents Page] [Next section]

Inside the System File (Continued)

QuickDraw Text

QuickDraw Text is the part of the MacOS used for drawing and displaying textual information on the screen and other raster devices.
  • A new Gestalt selector, gestaltQDTextVersion ('qdtx'), has been defined in this release of QuickDraw Text. With this release of QuickDraw Text, the value returned is gestaltAllegroQDText.

COMPATIBILITY NOTE
The new QuickDraw Text routines described in this section are available only if the result returned by a call to Gestalt with the selector gestaltQDTextVersion is greater than or equal to the constant gestaltAllegroQDText.

  • Support for anti-aliased text has been added to QuickDraw Text. Anti-aliased text drawing will occur if it is enabled, the destination device pixel depth is greater than or equal to 8 bits, there is sufficient memory available, the requested font size for drawing is larger than the minimum size for anti-aliased drawing, and the font being drawn is an outline font. Two new routines for accessing the state of anti-aliased text drawing can be called from PowerPC applications linking against the shared library FontManager included in the System file. The routines are defined as follows:

    IsAntiAliasedTextEnabled

    Boolean IsAntiAliasedTextEnabled(SInt16* outMinFontSize);

    outMinFontSize is an optional parameter and may be set to NULL. If outMinFontSize is not NULL, then the sixteen bit integer at that address will be set to the current lower size limit for antialiasing text (as set in the Appearance Control Panel).

    The function IsAntiAliasedTextEnabled returns true if anti-aliased text display is enabled.

    SetAntiAliasedTextEnabled

    OSStatus SetAntiAliasedTextEnabled(Boolean inEnable,
                                       SInt16 inMinFontSize);

    inEnable indicates the desired state of the anti-aliased text drawing. If inEnable is true, then both anti-aliased text drawing will be turned on and the QuickDraw Text global variable outlinePreferred will be turned on.

    inMinFontSize defines the smallest size font that should be drawn as anti-aliased text. This value must be in the range 1 through 128. If the inMinFontSize parameter is outside of this range, then the default value 12 is used.

    SetAntiAliasedTextEnabled always returns noErr.

    NOTE: For fonts which have both bitmaps ('NFNT's) and outlines ('sfnt's), the implicit change in outlinePreferred may change the metrics for the bitmap font sizes.

WARNING:
Calls to SetAntiAliasedTextEnabled should only be made under special circumstances when greater control over text display during particular operations is desired. Developers changing the state of anti-aliased text drawing must restore its original state before returning control to the system. Failure to do so may result in other parts of the system, most notably the Appearance control panel, becoming out of sync with the actual state of anti-aliased text drawing.

  • Two new routines for retrieving the pixel dimensions of text that will be drawn on the screen have been added to QuickDraw Text. These routines can be called from PowerPC applications linking against the shared library FontManager in the System file. The new routines are defined as follows:

    QDTextBounds

    void QDTextBounds(short byteCount,
                      const void* textAddr,
                      Rect* bounds);

    byteCount is the number of bytes of text contained in the buffer located at the address contained in the value textAddr.

    textAddr points to byteCount bytes of textual data.

    bounds is a pointer to a Rect structure whose coordinates will be calculated by QDTextBounds. On return, bounds will contain the bounding coordinates for the entire image (including parts of the image that may extend beyond the first and last pen positions after the text has been drawn) that will be drawn for the text (given the font settings in the current GrafPort). Note that the coordinates returned are relative to the current pen position (as if the pen were located at the origin). For example, in Listing 3, we use QDTextBounds to draw a rectangle around the text's image. Notice how in this example the bounds returned by QDTextBounds are offset using the current pen position, so that the text drawing and the rectangle drawing occur using the same coordinate system.

    Listing 3. Using QDTextBounds to discover where text will be drawn.

    Rect bounds;
    char *text = "sample text";
    Point where;
    SetPt(&where, 100, 100);
    MoveTo(where.h, where.v);
    PenSize(1,1);
    QDTextBounds(text, strlen(text), &bounds);
    OffsetRect(&bounds, where.h, where.v);
    InsetRect(&bounds, -1, -1);
    FrameRect(&bounds);
    DrawText(text, 0, strlen(text));

    The leftmost edge of the text's image can either be to the right or the left of the pen postition, and the rightmost edge of the text's image may be to the left or the right of the final pen position.

    FetchFontInfo

    OSErr FetchFontInfo(SInt16 fontID,
                        SInt16 fontSize,
                        SInt16 fontStyle,
                        FontInfo* info);

    fontID is the font ID number for a font.

    fontSize is the font size in pixels.

    fontStyle contains the font style flags for the font.

    info is a pointer to a font information record where the result will be stored.

    FetchFontInfo returns the same information as GetFontInfo, except, rather than gathering information about the font settings from the current GrafPort, this information is provided as parameters to the routine. If FetchFontInfo returns an error, the fields in the FontInfo record will be set to zero. (The error code returned is the value returned by FMSwapFont.)

    Related Materials:

[Previous section] [Mac OS 8.5 Contents Page] [Next section]

To contact us, please use the Contact Us page.